// filename: MainListLayout.cpp
// author: enic
// date: 2015-11-09

#include "MainListLayout.h"

namespace DuiLib
{

	MainListLayout::MainListLayout()
	{

	}

	MainListLayout::~MainListLayout()
	{

	}

	void MainListLayout::DoInit()
	{
		X_DUI_FIND_SUB_CONTROL(this, m_pTab, _T("tabs"), CTabLayoutUI);
		X_DUI_FIND_SUB_CONTROL(this, m_pEAUserTreeList, _T("friends"), CEAUserTreeListUI);
		X_DUI_FIND_SUB_CONTROL(this, m_pGroupList, _T("groupsList"), CGroupsTreeListUI);
		X_DUI_FIND_SUB_CONTROL(this, m_pUIRecentConnectedList, _T("recentlyList"), CUIRecentSessionList);

		//m_pEAUserTreeList->OnNotify += MakeDelegateNew(this, &MainListLayout::OntifyDelegate, std::wstring(DUI_MSGTYPE_ITEMCLICK));
		//m_pEAUserTreeList->OnNotify += MakeDelegateNew(this, &MainListLayout::OntifyDelegate, std::wstring(DUI_MSGTYPE_ITEMSELECT));
		//m_pEAUserTreeList->OnNotify += MakeDelegateNew(this, &MainListLayout::OntifyDelegate, std::wstring(DUI_MSGTYPE_ITEMACTIVATE));
		//m_pEAUserTreeList->OnNotify += MakeDelegateNew(this, &MainListLayout::OntifyDelegate, std::wstring(DUI_MSGTYPE_ITEMDBCLICK));

		AddTestDate();
	}

	void MainListLayout::OntifyDelegate(TNotifyUI& notify)
	{
		int i = 0;
		i++;

		SessionDialog* pDlg = new SessionDialog;
		pDlg->Create(NULL, _T("SessionDialog"), UI_CLASSSTYLE_DIALOG, WS_EX_STATICEDGE | WS_EX_APPWINDOW, 0, 0, 0, 0);
		pDlg->CenterWindow();
		bool bRet = true;
		bRet = (IDOK == pDlg->ShowModal());
	}


	void MainListLayout::AddTestDate()
	{
		for (int i = 0; i < 9; i++)
		{
			CListContainerElementUI* pListElement = NULL;
			CDialogBuilder dlgBuilder;
			if( !dlgBuilder.GetMarkup()->IsValid() ) {
				pListElement = static_cast<CListContainerElementUI*>(dlgBuilder.Create(_T("MainDialog\\eaUserListItem.xml"), (UINT)0, NULL, m_pManager));
			}
			else {
				pListElement = static_cast<CListContainerElementUI*>(dlgBuilder.Create((UINT)0, m_pManager));
			}

			m_pEAUserTreeList->Add(pListElement);

			pListElement->OnNotify += MakeDelegateNew(this, &MainListLayout::OntifyDelegate, std::wstring(DUI_MSGTYPE_ITEMCLICK));
		}
	}

	void MainListLayout::SwitchView(EM_MainListLayout emSwitch)
	{
		m_pTab->SelectItem((uint32_t)emSwitch);
	}
};
